<%-- 
    Document   : ValidaUsuarioPermiso
    Created on : 7/10/2011, 10:30:00 AM
    Author     : Ces
--%>

<%@ page import="PaquetesJL.*" %>
<%@page import="java.sql.ResultSet" %>

<%
        HttpSession objSesion = request.getSession(false); 
        String usuario = (String)objSesion.getAttribute("username");
        String validatePage = request.getParameter("id");
                
        
        String sqlServer = pageContext.getServletContext().getInitParameter("sqlServer");
        String databaseName = pageContext.getServletContext().getInitParameter("databaseName");
        String userName = pageContext.getServletContext().getInitParameter("userName");
        String PasswordP = pageContext.getServletContext().getInitParameter("password");
        String Backup = pageContext.getServletContext().getInitParameter("RutaBackup");
        
        byte[] decodedBytes = ConexionBD.decode(PasswordP);
        String decodedPassword = new String(decodedBytes).trim();
        
        ConexionBD Conexion = new ConexionBD(sqlServer, databaseName, userName, decodedPassword, Backup);
        Conexion.IniciarConexion();
        
        ResultSet r = Conexion.EjecutarConsulta("EXEC [ValidarUsuarioPermiso] @Login = '"+usuario+"', @Accion ='"+validatePage+"'");
        
        try {
        
            if(r.next())
            {
                if(r.getString(1).equals("0"))
                {                    
                    response.sendRedirect("index.jsp");
                    objSesion.setAttribute("valido", null);
                }
                else
                {
                    objSesion.setAttribute("valido", "true");
                }
            }
        
        } catch (NullPointerException e) { out.println(e.getMessage()); }

        Conexion.CerrarConexion();
    
    
%>